import React, { Component } from 'react'

import { Provider } from 'react-redux'
import { createStore, applyMiddleware } from 'redux'

import reducers from '_redux/reducers'
import Cookies from 'js-cookie'
import Header from './common/Header'
import Banner from './common/Banner'
import OpenLayer from 'map/OpenLayer'

import Appends from './Appends'

import User from './user/User'
import Tools from './tools/Tools'
import { getUserToken } from 'utils/Api'
import history from '../history'
import Company from './common/Company'
import thunk from 'redux-thunk'
import DragDrops from './DragDrops'

const store = createStore(reducers, {}, applyMiddleware(thunk))
class FineGrainApp extends Component {
  componentDidMount() {
    if (!Cookies.get('name')) {
      history.push('/')
    }
    const token = getUserToken()
    if (!token) {
      history.push('/')
      return
    }
  }
  render() {
    return (
      <Provider store={store}>
        <div>
          <Header />
          <Company />
          <Tools />
          <User />
          <OpenLayer />
          <DragDrops/>
          <Banner />
          <Appends/>
        </div>
      </Provider>
    )
  }
}
export default FineGrainApp